package jianzhiOffer;

import java.util.Deque;
import java.util.LinkedList;

public class num58_1 {
    public String reverseWords(String s) {
        Deque<String> stack = new LinkedList<>();
        String[] strs = s.split(" ");
        int len = strs.length;
        for(int i = 0;i < len; i++) {
            if(strs[i] != "")
            stack.push(strs[i]);
        }
        StringBuilder sb = new StringBuilder();
        while(!stack.isEmpty()) {
            sb.append(stack.pop());
            if(!stack.isEmpty()) {
                sb.append(" ");
            }
        }
        return sb.toString();
    }
}
